package com.dwxt.mall.service;

import com.dwxt.common.base.YesOrNo;
import com.dwxt.mall.dao.ProductCategoryMapper;
import com.dwxt.mall.entity.ProductCategory;
import com.dwxt.mall.entity.ProductCategoryExample;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductAttrService {

    @Autowired
    private ProductCategoryMapper productCategoryMapper;

    public List<ProductCategory> selectProductCategoryList(String module) {
        ProductCategoryExample example = new ProductCategoryExample();
        ProductCategoryExample.Criteria criteria = example.createCriteria();
        criteria.andIsShowEqualTo(YesOrNo.YES).andIsOnEqualTo(YesOrNo.YES);
        if (StringUtils.isNotBlank(module)) {
            criteria.andModuleEqualTo(module);
        }
        return productCategoryMapper.selectByExample(example);
    }

    public ProductCategory selectProductCategoryByName(String name) {
        ProductCategoryExample example = new ProductCategoryExample();
        example.createCriteria().andNameEqualTo(name);
        List<ProductCategory> productCategoryList = productCategoryMapper.selectByExample(example);
        return productCategoryList.size() > 0 ? productCategoryList.get(0) : null;
    }
}
